<template>
  <div class="dashboard-editor-container">
    <panel-group @handleSetLineChartData="handleSetLineChartData" />
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;" :gutter="40">
      <el-col :span="13">
       <!-- <el-card :body-style="{ padding: '10px' }" shadow="always"> -->
          <line-chart :chart-data="lineChartData" />
        <!-- </el-card> -->
      </el-col>

      <el-col :span="10" >
        <!-- <el-card :body-style="{ padding: '10px' }" shadow="always"> -->
          <div ref="chart" style="width: 600px;height: 300px;"></div>
        <!-- </el-card> -->
      </el-col>
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="button-text">域名类型统计</div>
          <pie-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="button-text">模型特性比较</div>
          <raddar-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="button-text">参数性能统计</div>
          <bar-chart />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>

import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'

import echarts from 'echarts';

const lineChartData = {
  newVisitis: {
    expectedData: [60, 30, 91, 54, 42, 33, 15],
    actualData: [100, 120, 161, 134, 105, 160, 165],
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    // GithubCorner,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    // TransactionTable,
    // TodoList,
    // BoxCard
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis
    }
  },
  mounted() {
    this.getDateData()
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },

    getDateData() {
       // 模拟数据start
       function getVirtulData(year) {
          year = year || '2017';
          var date = +echarts.number.parseDate(year + '-01-01');
          var end = +echarts.number.parseDate((+year + 1) + '-01-01');

          var s = +echarts.number.parseDate(year + '-03-16');
          var e = +echarts.number.parseDate(year + '-05-07');
          var e2 = +echarts.number.parseDate(year + '-06-14');

          var dayTime = 3600 * 24 * 1000;
          var data = [];
          // for (var time = date; time < end; time += dayTime) {
          //     data.push([
          //         echarts.format.formatTime('yyyy-MM-dd', time),
          //         Math.floor(Math.random() * 10000)
          //     ]);
          // }
         for (var time = date; time < end; time += dayTime) {
                 if(time<s) {
                   data.push([
                       echarts.format.formatTime('yyyy-MM-dd', time),
                       Math.floor((Math.random()/3) * 1000)
                   ]);
                 } else if(time>=s && time<=e) {
                   data.push([
                       echarts.format.formatTime('yyyy-MM-dd', time),
                       Math.floor(Math.random() * 1000)
                   ]);
                 } else if(time>e && time<=e2) {
                   data.push([
                       echarts.format.formatTime('yyyy-MM-dd', time),
                       Math.floor(Math.random()/2.5 * 1000)
                   ]);
                 }
                 else {
                   data.push([
                       echarts.format.formatTime('yyyy-MM-dd', time),
                       Math.floor(0 * 1000)
                   ]);
                 }
               }
          console.log(data)
          return data;
       }
       // 模拟数据end
       let chartDom = echarts.init(this.$refs.chart);
       let option = {
          title: {
              top: 30,
              left: 'center',
              text: '恶意域名捕获数量的时间分布'
          },
          tooltip: {},
          visualMap: {
              min: 0,
              max: 1000,
              type: 'piecewise',
              orient: 'horizontal',
              left: 'center',
              top: 65,
              textStyle: {
                  color: '#000'
              }
          },
          calendar: {
              top: 120,
              left: 30,
              right: 30,
              cellSize: ['auto', 13],
              range: '2016',
              itemStyle: {
                  borderWidth: 0.5
              },
              yearLabel: {show: false}
          },
          series: {
              type: 'heatmap',
              coordinateSystem: 'calendar',
              data: getVirtulData(2016)
          }
      };
      chartDom && chartDom.setOption(option);
      chartDom.resize();
      let sizeFun = () => {
        chartDom.resize();
      };
      window.addEventListener("resize", sizeFun);
      this.$once("hook:beforeDestroy", function () {
        echarts.dispose(chartDom);
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 22px;
  background-color: rgb(240, 242, 245);
  // background-color: #394056;
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;

    .button-text {
      line-height: 18px;
      font-weight: bold;
      color: rgba(0, 0, 0, 0.45);
      font-size: 16px;
      margin-bottom: 12px;
    }
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}


</style>
